use rbs::to_value;
use rocket::{get, serde::json::Json, FromForm, State};
use serde::{Deserialize, Serialize};

use crate::Context;

use super::Resp;

#[derive(Debug,Clone,Serialize,Deserialize,FromForm)]
pub struct Command{
    pub id:Option<String>,
    pub code:Option<String>,
    pub route:Option<String>,
}

rbatis::crud!(Command{},"tb_command");

#[get("/command?<code>")]
pub async fn get_command(ctx:&State<Context>,code:&str) -> Json<Resp<Command>>{
    let cmd:Command = ctx.database.db.query_decode("select * from public.tb_command where code=?", vec![to_value!(code)]).await.unwrap();
    let resp=Resp::new(200, "success".to_string(), vec![cmd]);
    return Json(resp);
}
